﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using FA.FlightAttendant.Plugin;
using FA.FlightAttendant.Host;
using System.Threading;

namespace FA.FlightAttendant
{
    public static class Program
    {
        public static event ParameterlessEventHandler Initialised;
        public static event EventHandler<TextEventArgs> StatusChanged;

        public static string Status
        {
            get { return _status; }
            set
            {
                if (_status != value)
                {
                    _status = value;
                    if (StatusChanged != null)
                        StatusChanged(null, new TextEventArgs(_status));
                }
            }
        }
        private static string _status;

        public static bool IsInitialised
        {
            get { return _isInitialised; }
            set
            {
                _isInitialised = value;
                if (_isInitialised && Initialised != null)
                    Initialised();

            }
        }
        private static bool _isInitialised;

        public static void Initialise()
        {
            /* Disabled until UI-threading conflicts can resolved
             * 
            // Initialise the program in a seperate thread
            Thread initThread = new Thread(() =>
                {
                    Status = "Loading Plugin Libraries...";
                    PluginFactory.Instance.LoadPluginLibraries();

                    Status = "Loading Plugins...";
                    PluginHost.Instance.LoadPlugins();

                    Status = "Done!";
                    IsInitialised = true;
                });
            initThread.Start();
             */

            Status = "Loading Plugin Libraries...";
            PluginFactory.Instance.LoadPluginLibraries();

            Status = "Loading Plugins...";
            SimHost.Instance.LoadSimulators();

            Status = "Done!";
            IsInitialised = true;
        }
    }
}
